﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace Aandelendelen.SiteMessage
{
	public class SiteMessageCache
	{
		internal static SiteMessageCollection GetSiteMessages()
		{
			string cacheName = "sitemessage";

			SiteMessageCollection siteMessages = SiteMessageCache.Cache[cacheName] as SiteMessageCollection;

			if (siteMessages == null)
			{
				siteMessages = new SiteMessageCollection();

				CacheDependency dependency = new CacheDependency(HttpContext.Current.Server.MapPath("/App_Data/SiteMessage.xml"));

				SiteMessageCache.Cache.Insert(cacheName, siteMessages, dependency);
			}

			return siteMessages;
		}

		private static Cache Cache
		{
			get { return HttpContext.Current.Cache; }
		}
	}
}